import { Text, View } from '@tarojs/components';
import { HouseConstant } from '@/constant/HouseConstant';
import './index.less';
import { HouseEntity } from '@/entities/HouseEntity';
import { LeaseEntity } from '@/entities/LeaseEntity';

interface IProps {
  houses?: HouseEntity.IResultHouse | LeaseEntity.IHouseLease;
}

const ShowHouseMessage = (props: IProps) => {
  const {houses} = props;
  // 房屋信息展示字段
  const houseMessage = ['area', 'floor', 'toward', 'toilet', 'kitchen', 'balcony', 'addressName', 'addressInfo', 'note'];

  /**
   * 信息转换
   * @param field 字段
   * @param info 信息
   */
  const infoConvert = (field: string, info: string | number) => {
    if (field === 'toward') {
      return HouseConstant.TowardToNameMap[info];
    } else if (field === 'toilet') {
      return HouseConstant.ToiletToNameMap[info];
    } else if (field === 'kitchen') {
      return HouseConstant.KitchenToNameMap[info];
    } else if (field === 'balcony') {
      return HouseConstant.BalconyToNameMap[info];
    } else if (field === 'addressInfo') {
      return `${ houses?.provinceName }${ houses?.cityName }${ houses?.areaName }${ info }`;
    }
    return info;
  };

  return (
    <>
      <View className='house-message-container'>
        <View className='title font-bold'>房屋信息</View>
        {
          houseMessage.map((item: string, idx: number) => {
            return (
              <View key={ idx } className='info-item'>
                <Text className='text'>{ HouseConstant.FieldToNameMap[item] }</Text>
                <View>
                  <Text className='house-message-content'>
                    { infoConvert(item, houses?.[item]) }
                  </Text>
                  <Text className='unit'>{ HouseConstant.FieldToUnit[item] }</Text>
                </View>
              </View>
            );
          })
        }
      </View>
    </>
  );
};

export default ShowHouseMessage;